package com.tepth.vehiclemaintenance.mvp.login;

import android.content.pm.PackageManager;

import com.tepth.vehiclemaintenance.MyApplication;
import com.tepth.vehiclemaintenance.bean.User;
import com.tepth.vehiclemaintenance.config.AppInfo;
import com.tepth.vehiclemaintenance.net.ApiModel;
import com.tepth.vehiclemaintenance.net.Network;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by TMVPHelper on 2017/05/09
 */
public class LoginModel implements LoginContract.Model {

    @Override
    public Observable<ApiModel<User>> onLogin(String account, String password) {
        String versionName = "5.1";
        try {
            versionName = MyApplication.getContext().getPackageManager().getPackageInfo(
                    MyApplication.getContext().getPackageName(), 0).versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return Network.getApiService().login(account, password, AppInfo.APP_NAME,
                versionName, AppInfo.OS_NAME, AppInfo.OS_VERSION)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
}